<template>
  <div class="details">
    <el-card>
      <el-tabs v-model="activeName">
        <el-tab-pane label="登录账户设置" name="first">
          <el-form :model="form" label-width="80px" class="myform">
            <el-form-item label="姓名：">
              <el-input v-model="form.username" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="密码：">
              <el-input
                v-model="form.password"
                placeholder="请输入"
                type="password"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="small" @click="update"
                >更新</el-button
              >
              <el-button type="primary" size="small">取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second">
          <userinfo></userinfo>
        </el-tab-pane>
        <el-tab-pane label="岗位信息" name="third">
          <jobinfo></jobinfo>
        </el-tab-pane>
        <el-tab-pane class="print">
          <template #label>
              <i class="el-icon-printer" @click="toPrint">打印</i>
              
          </template>
          </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { getEmployeesApi, setEmployeesApi } from '@/api/employees'
export default {
  name: 'detail',
  components: {
    userinfo: () => import('../components/userInfo.vue'),
    jobinfo: () => import('../components/jobInfo.vue')
  },
  data () {
    return {
      activeName: 'first',
      form: {
        username: '',
        password: ''
      },
      id: this.$route.params.id,
      type: ''
    }
  },
  methods: {
    async getEmployees () {
      const res = await getEmployeesApi(this.id)
      //   console.log(res)
      this.form = { ...res.data }
    },
    async update () {
      try {
        await setEmployeesApi(this.form)
        this.$message.success('更新成功')
        this.$router.push('/employees')
      } catch (error) {
        console.log(error)
      }
    },
    toPrint () {
      this.activeName==="first" || this.activeName==="second" ? this.type="info" : this.type="job"
      this.$router.push(`/employees/print/${this.id}?type=${this.type}`)
    }
  },
  created () {
    this.getEmployees()
  }
}
</script>

<style lang="scss" scoped>
.details {
  position: relative;
  padding: 20px;

  .el-input {
    width: 300px;
  }

  .myform {
    margin: 40px 0 0 300px;
  }
.print {
  position: absolute;
  right: 0;
}
}

</style>
